{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "y8L9VFhhdjhL"
   },
   "source": [
    "# Financial Coaching Agent using PraisonAIAgents"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "6UxqTg7pdkm-"
   },
   "source": [
    "This notebook demonstrates how to build a Financial Coaching Agent using the `praisonaiagents` library.\n",
    "The agent analyzes user financial data and provides actionable recommendations for budgeting, savings, and debt management.\n",
    "The notebook is CI-friendly: it uses dummy data if API keys are not set, so all tests/checks will pass."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "CNqB5dPffV3m"
   },
   "source": [
    "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Dhivya-Bharathy/PraisonAI/blob/main/examples/cookbooks/Finance_Market_Job_Agents/Financial_Coaching_Agent.ipynb)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "3cdm72N2doNq"
   },
   "source": [
    "# Dependencies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "Pl85wGWzdpTK"
   },
   "outputs": [],
   "source": [
    "!pip install praisonaiagents pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "YOlEEkk4ePqy"
   },
   "source": [
    "# Set up key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "id": "T9zKRkv_eRsc"
   },
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "# Try to get keys from environment variables, or use placeholders\n",
    "OPENAI_API_KEY = os.environ.get(\"OPENAI_API_KEY\", \"sk-..\")\n",
    "\n",
    "# Set them in the environment for downstream code\n",
    "os.environ[\"OPENAI_API_KEY\"] = OPENAI_API_KEY\n",
    "\n",
    "def is_valid_key(key, prefix):\n",
    "    return key and key != f\"{prefix}-..\" and key.startswith(prefix)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "FGYJpB9eeaSY"
   },
   "source": [
    "# Tool: Financial Summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "id": "asLRt9gAecJ2"
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "class FinancialSummaryTool:\n",
    "    \"\"\"\n",
    "    Custom tool to summarize financial data and calculate basic stats.\n",
    "    \"\"\"\n",
    "    def __init__(self, income, expenses, debts):\n",
    "        self.income = income\n",
    "        self.expenses = expenses\n",
    "        self.debts = debts\n",
    "\n",
    "    def summary(self):\n",
    "        total_expenses = sum(self.expenses.values())\n",
    "        surplus = self.income - total_expenses\n",
    "        total_debt = sum(d['amount'] for d in self.debts)\n",
    "        return {\n",
    "            \"total_expenses\": total_expenses,\n",
    "            \"surplus\": surplus,\n",
    "            \"total_debt\": total_debt,\n",
    "            \"expense_breakdown\": self.expenses,\n",
    "            \"debts\": self.debts\n",
    "        }"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "lIysLOOdef3b"
   },
   "source": [
    "# YAML prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "GDbWRmp2egsz",
    "outputId": "cf4e4d15-7446-4613-9a20-298674f0b4d3"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'agent': {'name': 'Financial Coaching Agent', 'description': 'An agent that analyzes user financial data and provides actionable recommendations for budgeting, savings, and debt management.\\n', 'tools': [{'name': 'FinancialSummaryTool', 'description': 'Summarizes income, expenses, and debts for the agent.'}], 'workflow': [{'step': 'Summarize financial data using FinancialSummaryTool'}, {'step': 'Analyze summary and provide recommendations'}]}, 'inputs': ['monthly_income', 'expenses', 'debts'], 'outputs': ['recommendations']}\n"
     ]
    }
   ],
   "source": [
    "import yaml\n",
    "\n",
    "yaml_prompt = \"\"\"\n",
    "agent:\n",
    "  name: Financial Coaching Agent\n",
    "  description: |\n",
    "    An agent that analyzes user financial data and provides actionable recommendations for budgeting, savings, and debt management.\n",
    "  tools:\n",
    "    - name: FinancialSummaryTool\n",
    "      description: Summarizes income, expenses, and debts for the agent.\n",
    "  workflow:\n",
    "    - step: Summarize financial data using FinancialSummaryTool\n",
    "    - step: Analyze summary and provide recommendations\n",
    "inputs:\n",
    "  - monthly_income\n",
    "  - expenses\n",
    "  - debts\n",
    "outputs:\n",
    "  - recommendations\n",
    "\"\"\"\n",
    "print(yaml.safe_load(yaml_prompt))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "C-FE-hTKekHK"
   },
   "source": [
    "# Main"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000,
     "referenced_widgets": [
      "b27151e0a1ec47d8a36433ef503eede2",
      "58e152a95c1d49d68b45aea3b837b6d3"
     ]
    },
    "id": "48oIH5LYek-q",
    "outputId": "b501eae2-63c2-434d-f5c3-abba6b93956e"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">╭─ </span><span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8; font-weight: bold\">Agent Info</span><span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\"> ────────────────────────────────────────────────────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>                                                                                                                 <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>  <span style=\"color: #ff9b9b; text-decoration-color: #ff9b9b; font-weight: bold\">👤 Agent:</span> <span style=\"color: #ffe5e5; text-decoration-color: #ffe5e5\">Financial Coaching Agent</span>                                                                             <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>  <span style=\"color: #b4b4b3; text-decoration-color: #b4b4b3; font-weight: bold\">Role:</span> <span style=\"color: #ffe5e5; text-decoration-color: #ffe5e5\">Assistant</span>                                                                                                <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>                                                                                                                 <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[38;2;210;227;200m╭─\u001b[0m\u001b[38;2;210;227;200m \u001b[0m\u001b[1;38;2;210;227;200mAgent Info\u001b[0m\u001b[38;2;210;227;200m \u001b[0m\u001b[38;2;210;227;200m───────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\u001b[38;2;210;227;200m─╮\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m                                                                                                                 \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m  \u001b[1;38;2;255;155;155m👤 Agent:\u001b[0m \u001b[38;2;255;229;229mFinancial Coaching Agent\u001b[0m                                                                             \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m  \u001b[1;38;2;180;180;179mRole:\u001b[0m \u001b[38;2;255;229;229mAssistant\u001b[0m                                                                                                \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m                                                                                                                 \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b27151e0a1ec47d8a36433ef503eede2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Output()"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">Response generated in 11.0s</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2mResponse generated in 11.0s\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008080; text-decoration-color: #008080\">╭───────────────────────────────────────────────────── Task ──────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> You are a financial coach. Analyze the following summary and provide actionable recommendations: - Monthly      <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> income: $3000 - Total expenses: $2350 - Surplus: $650 - Total debt: $10000 - Expense breakdown: {'Housing':     <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> 1200, 'Food': 400, 'Transportation': 200, 'Entertainment': 150, 'Savings': 300, 'Other': 100} - Debts:          <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> [{'name': 'Credit Card', 'amount': 2000, 'interest_rate': 18.0, 'min_payment': 50}, {'name': 'Student Loan',    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> 'amount': 8000, 'interest_rate': 5.0, 'min_payment': 100}]                                                      <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[36m╭─\u001b[0m\u001b[36m────────────────────────────────────────────────────\u001b[0m\u001b[36m Task \u001b[0m\u001b[36m─────────────────────────────────────────────────────\u001b[0m\u001b[36m─╮\u001b[0m\n",
       "\u001b[36m│\u001b[0m You are a financial coach. Analyze the following summary and provide actionable recommendations: - Monthly      \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m income: $3000 - Total expenses: $2350 - Surplus: $650 - Total debt: $10000 - Expense breakdown: {'Housing':     \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m 1200, 'Food': 400, 'Transportation': 200, 'Entertainment': 150, 'Savings': 300, 'Other': 100} - Debts:          \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m [{'name': 'Credit Card', 'amount': 2000, 'interest_rate': 18.0, 'min_payment': 50}, {'name': 'Student Loan',    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m 'amount': 8000, 'interest_rate': 5.0, 'min_payment': 100}]                                                      \u001b[36m│\u001b[0m\n",
       "\u001b[36m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008080; text-decoration-color: #008080\">╭─────────────────────────────────────────────────── Response ────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> Based on the provided financial summary, here are some actionable recommendations to help manage your finances  <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> more effectively and reduce your debt:                                                                          <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                                                                                                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 1 </span><span style=\"font-weight: bold\">Prioritize Debt Repayment:</span>                                                                                   <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>Focus on paying off the high-interest debt first, which is the credit card debt with an 18% interest      <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>rate. Consider using the debt avalanche method, where you pay extra towards the debt with the highest     <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>interest rate while making minimum payments on others.                                                    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>With a surplus of $650, allocate a significant portion of this towards the credit card debt. For example, <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>you could pay $400 towards the credit card debt (including the $50 minimum payment), which would help     <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>reduce the principal faster and save on interest.                                                         <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 2 </span><span style=\"font-weight: bold\">Review and Adjust Expenses:</span>                                                                                  <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span><span style=\"font-weight: bold\">Housing:</span> At $1200, housing is a significant portion of your expenses. If possible, explore options to     <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>reduce this cost, such as negotiating rent, finding a roommate, or moving to a less expensive place.      <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span><span style=\"font-weight: bold\">Food:</span> Consider meal planning, cooking at home, and reducing dining out to lower the $400 food expense.    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span><span style=\"font-weight: bold\">Entertainment:</span> At $150, see if you can cut back on discretionary spending. Look for free or low-cost      <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>entertainment options.                                                                                    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span><span style=\"font-weight: bold\">Other Expenses:</span> Review the $100 in 'Other' expenses to identify any non-essential spending that can be    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>reduced or eliminated.                                                                                    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 3 </span><span style=\"font-weight: bold\">Increase Savings:</span>                                                                                            <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>While you are already saving $300 monthly, consider increasing this amount once the high-interest debt is <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>paid off. Building an emergency fund should be a priority to cover 3-6 months of expenses.                <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 4 </span><span style=\"font-weight: bold\">Boost Income:</span>                                                                                                <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>Explore opportunities to increase your income, such as taking on a part-time job, freelancing, or selling <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>unused items. Any additional income can accelerate debt repayment and increase savings.                   <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 5 </span><span style=\"font-weight: bold\">Monitor and Adjust:</span>                                                                                          <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>Regularly review your budget and expenses to ensure you are on track with your financial goals. Adjust    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>your plan as needed to accommodate changes in income or expenses.                                         <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 6 </span><span style=\"font-weight: bold\">Consider Debt Consolidation:</span>                                                                                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">    • </span>If you have a good credit score, look into consolidating your credit card debt into a lower-interest      <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">      </span>personal loan. This could reduce your overall interest payments and simplify your debt repayment process. <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                                                                                                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> By implementing these recommendations, you can effectively manage your finances, reduce debt, and work towards  <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> achieving greater financial stability.                                                                          <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[36m╭─\u001b[0m\u001b[36m──────────────────────────────────────────────────\u001b[0m\u001b[36m Response \u001b[0m\u001b[36m───────────────────────────────────────────────────\u001b[0m\u001b[36m─╮\u001b[0m\n",
       "\u001b[36m│\u001b[0m Based on the provided financial summary, here are some actionable recommendations to help manage your finances  \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m more effectively and reduce your debt:                                                                          \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                                                                                                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m 1 \u001b[0m\u001b[1mPrioritize Debt Repayment:\u001b[0m                                                                                   \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mFocus on paying off the high-interest debt first, which is the credit card debt with an 18% interest      \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mrate. Consider using the debt avalanche method, where you pay extra towards the debt with the highest     \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0minterest rate while making minimum payments on others.                                                    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mWith a surplus of $650, allocate a significant portion of this towards the credit card debt. For example, \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0myou could pay $400 towards the credit card debt (including the $50 minimum payment), which would help     \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mreduce the principal faster and save on interest.                                                         \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m 2 \u001b[0m\u001b[1mReview and Adjust Expenses:\u001b[0m                                                                                  \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0m\u001b[1mHousing:\u001b[0m At $1200, housing is a significant portion of your expenses. If possible, explore options to     \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mreduce this cost, such as negotiating rent, finding a roommate, or moving to a less expensive place.      \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0m\u001b[1mFood:\u001b[0m Consider meal planning, cooking at home, and reducing dining out to lower the $400 food expense.    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0m\u001b[1mEntertainment:\u001b[0m At $150, see if you can cut back on discretionary spending. Look for free or low-cost      \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mentertainment options.                                                                                    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0m\u001b[1mOther Expenses:\u001b[0m Review the $100 in 'Other' expenses to identify any non-essential spending that can be    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mreduced or eliminated.                                                                                    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m 3 \u001b[0m\u001b[1mIncrease Savings:\u001b[0m                                                                                            \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mWhile you are already saving $300 monthly, consider increasing this amount once the high-interest debt is \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mpaid off. Building an emergency fund should be a priority to cover 3-6 months of expenses.                \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m 4 \u001b[0m\u001b[1mBoost Income:\u001b[0m                                                                                                \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mExplore opportunities to increase your income, such as taking on a part-time job, freelancing, or selling \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0munused items. Any additional income can accelerate debt repayment and increase savings.                   \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m 5 \u001b[0m\u001b[1mMonitor and Adjust:\u001b[0m                                                                                          \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mRegularly review your budget and expenses to ensure you are on track with your financial goals. Adjust    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0myour plan as needed to accommodate changes in income or expenses.                                         \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m 6 \u001b[0m\u001b[1mConsider Debt Consolidation:\u001b[0m                                                                                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m • \u001b[0mIf you have a good credit score, look into consolidating your credit card debt into a lower-interest      \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m   \u001b[0m\u001b[1;33m   \u001b[0mpersonal loan. This could reduce your overall interest payments and simplify your debt repayment process. \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                                                                                                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m By implementing these recommendations, you can effectively manage your finances, reduce debt, and work towards  \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m achieving greater financial stability.                                                                          \u001b[36m│\u001b[0m\n",
       "\u001b[36m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "=== Financial Coaching Agent Recommendations ===\n",
      "Based on the provided financial summary, here are some actionable recommendations to help manage your finances more effectively and reduce your debt:\n",
      "\n",
      "1. **Prioritize Debt Repayment:**\n",
      "   - Focus on paying off the high-interest debt first, which is the credit card debt with an 18% interest rate. Consider using the debt avalanche method, where you pay extra towards the debt with the highest interest rate while making minimum payments on others.\n",
      "   - With a surplus of $650, allocate a significant portion of this towards the credit card debt. For example, you could pay $400 towards the credit card debt (including the $50 minimum payment), which would help reduce the principal faster and save on interest.\n",
      "\n",
      "2. **Review and Adjust Expenses:**\n",
      "   - **Housing:** At $1200, housing is a significant portion of your expenses. If possible, explore options to reduce this cost, such as negotiating rent, finding a roommate, or moving to a less expensive place.\n",
      "   - **Food:** Consider meal planning, cooking at home, and reducing dining out to lower the $400 food expense.\n",
      "   - **Entertainment:** At $150, see if you can cut back on discretionary spending. Look for free or low-cost entertainment options.\n",
      "   - **Other Expenses:** Review the $100 in 'Other' expenses to identify any non-essential spending that can be reduced or eliminated.\n",
      "\n",
      "3. **Increase Savings:**\n",
      "   - While you are already saving $300 monthly, consider increasing this amount once the high-interest debt is paid off. Building an emergency fund should be a priority to cover 3-6 months of expenses.\n",
      "\n",
      "4. **Boost Income:**\n",
      "   - Explore opportunities to increase your income, such as taking on a part-time job, freelancing, or selling unused items. Any additional income can accelerate debt repayment and increase savings.\n",
      "\n",
      "5. **Monitor and Adjust:**\n",
      "   - Regularly review your budget and expenses to ensure you are on track with your financial goals. Adjust your plan as needed to accommodate changes in income or expenses.\n",
      "\n",
      "6. **Consider Debt Consolidation:**\n",
      "   - If you have a good credit score, look into consolidating your credit card debt into a lower-interest personal loan. This could reduce your overall interest payments and simplify your debt repayment process.\n",
      "\n",
      "By implementing these recommendations, you can effectively manage your finances, reduce debt, and work towards achieving greater financial stability.\n"
     ]
    }
   ],
   "source": [
    "from praisonaiagents import Agent\n",
    "\n",
    "# Dummy data for CI/public use\n",
    "dummy_financial_data = {\n",
    "    \"monthly_income\": 3000,\n",
    "    \"expenses\": {\n",
    "        \"Housing\": 1200,\n",
    "        \"Food\": 400,\n",
    "        \"Transportation\": 200,\n",
    "        \"Entertainment\": 150,\n",
    "        \"Savings\": 300,\n",
    "        \"Other\": 100\n",
    "    },\n",
    "    \"debts\": [\n",
    "        {\"name\": \"Credit Card\", \"amount\": 2000, \"interest_rate\": 18.0, \"min_payment\": 50},\n",
    "        {\"name\": \"Student Loan\", \"amount\": 8000, \"interest_rate\": 5.0, \"min_payment\": 100}\n",
    "    ]\n",
    "}\n",
    "\n",
    "income = dummy_financial_data[\"monthly_income\"]\n",
    "expenses = dummy_financial_data[\"expenses\"]\n",
    "debts = dummy_financial_data[\"debts\"]\n",
    "\n",
    "tool = FinancialSummaryTool(income, expenses, debts)\n",
    "summary = tool.summary()\n",
    "\n",
    "if not is_valid_key(OPENAI_API_KEY, \"sk\"):\n",
    "    print(\"API key not set or is a placeholder. Using dummy recommendations for CI/testing.\")\n",
    "    recommendations = \"\"\"\n",
    "    - Review your monthly expenses and identify areas to cut back.\n",
    "    - Increase your monthly savings by at least 10%.\n",
    "    - Pay off high-interest debts first (e.g., Credit Card).\n",
    "    - Build an emergency fund covering at least 3-6 months of expenses.\n",
    "    \"\"\"\n",
    "else:\n",
    "    prompt = f\"\"\"\n",
    "    You are a financial coach. Analyze the following summary and provide actionable recommendations:\n",
    "    - Monthly income: ${summary['surplus'] + summary['total_expenses']}\n",
    "    - Total expenses: ${summary['total_expenses']}\n",
    "    - Surplus: ${summary['surplus']}\n",
    "    - Total debt: ${summary['total_debt']}\n",
    "    - Expense breakdown: {summary['expense_breakdown']}\n",
    "    - Debts: {summary['debts']}\n",
    "    \"\"\"\n",
    "    agent = Agent(\n",
    "        name=\"Financial Coaching Agent\",\n",
    "        api_key=OPENAI_API_KEY\n",
    "    )\n",
    "    # Use start(prompt) instead of run()\n",
    "    recommendations = agent.start(prompt)\n",
    "\n",
    "print(\"=== Financial Coaching Agent Recommendations ===\")\n",
    "print(recommendations)"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
